package com.luo.service;

import com.luo.dao.GoodMappers;
import com.luo.dao.impl.GoodMappersImpl;
import com.luo.model.GoodByTwoClassId;
import com.luo.model.Goods;
import com.luo.model.TwoClass;

import java.util.List;
import java.util.Map;

/**
 * 功能：
 * 作者：Luo。
 * 日期：2024/1/9 19:57
 */
public class GoodService {
	GoodMappersImpl goodMappers = new GoodMappersImpl();

	public List<Goods> queryNewGoods() {
		List<Goods> goods = goodMappers.queryNewGoods();
		return goods;
	}

	public List<Goods> queryGoodsByTwoId(final String id) {
		List<Goods> goods = goodMappers.queryGoodsByTwoId(id);
		for (Goods good : goods) {
			Double disCount = Double.valueOf(good.getDiscount()) / 10;
			Double price = Double.valueOf(good.getPrice());
			if (disCount > 0.0) {
				good.setOldPrice(String.format("%.2f", price * disCount));
			} else {
				good.setOldPrice(String.format("%.2f", price));
			}
		}
		return goods;
	}

	public List<Goods> queryAllGoods() {
		List<Goods> goods = goodMappers.queryAllGoods();
		return goods;
	}

	public int updateGood(Goods goods) {
		int i = goodMappers.updateGood(goods);
		return i;
	}

	public int deleteGoodById(String id) {
		int i = goodMappers.deleteGoodById(id);
		return i;
	}

	public int deleteSomeGoodsById(List<String> strings) {
		int i = goodMappers.deleteSomeGoodsById(strings);
		return i;
	}

	public int addOneGood(final Goods goods) {
		int i = goodMappers.addOneGood(goods);
		return i;
	}

	public List<Goods> queryGoodSomeByTwoClassId(GoodByTwoClassId goodByTwoClassId) {
		List<Goods> goods = goodMappers.queryGoodSomeByTwoClassId(goodByTwoClassId);
		return goods;
	}

	public List<Goods> queryGoodByOneId(String id) {
		List<Goods> goods = goodMappers.queryGoodByOneId(id);
		return goods;
	}

	public Goods queryGoodBy(String id) {
		Goods goods = goodMappers.queryGoodBy(id);

		Double disCount = Double.valueOf(goods.getDiscount()) / 10;
		Double price = Double.valueOf(goods.getPrice());
		if (disCount > 0.0) {
			goods.setOldPrice(String.format("%.2f", price * disCount));
		} else {
			goods.setOldPrice(String.format("%.2f", price));
		}
		return goods;
	}

	public List<Goods> queryGoodsByNameLike(String name) {
		List<Goods> goods = goodMappers.queryGoodsByNameLike(name);
		for (Goods good : goods) {
			Double disCount = Double.valueOf(good.getDiscount()) / 10;
			Double price = Double.valueOf(good.getPrice());
			if (disCount > 0.0) {
				good.setOldPrice(String.format("%.2f", price * disCount));
			} else {
				good.setOldPrice(String.format("%.2f", price));
			}
		}
		return goods;
	}

}
